package com.csap.framework.boot.validation.autoconfigure;

import com.csap.framework.validation.ValidateIntercept;
import com.csap.framework.validation.factory.ValidateFactory;
import com.csap.framework.validation.properties.ValidationProperties;
import org.hibernate.validator.internal.metadata.core.ConstraintHelper;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

/**
 * validate config
 *
 * @author yangchengfu
 * @date 2021/1/6 10:18 上午
 **/
@Configuration
@EnableConfigurationProperties(ValidationProperties.class)
@ComponentScan("com.csap.framework.validation")
public class ValidationAutoConfiguration {

    @Bean
    public ConstraintHelper constraintHelper() {
        return ConstraintHelper.forAllBuiltinConstraints();
    }

    @Bean
    public ValidateIntercept validateIntercept(ValidateFactory validateFactory) {
        return new ValidateIntercept(validateFactory);
    }

    @Bean
    public ValidateFactory validateFactory(ConstraintHelper constraintHelper) {
        return new ValidateFactory(constraintHelper);
    }
}
